package za.org.jcicada.katcp;

/**
 * ISamplingStrategy.java
 *
 * @author Simon Cross
 *
 * Created on October 22, 2008, 17:31
 */

/**
 * Represents a KAT sensor sampling strategy.
 */
public interface ISamplingStrategy {

    /**
     * Sensor Sampling Strategies.
     */
    public enum Strategy {
        /** Don't sample the sensor. */ NONE,
        /** Sample the sensor periodically with a fixed period. */ PERIOD,
        /** Sample the sensor whenever the value changes. */ EVENT,
        /** Sample the sensor when the value changes by more than a given amount. */ DIFF,
        /** Sample the sensor whenever the value is updates. */ AUTO;

        /**
         * Return the name of the sampling strategy value.
         *
         * @return The KATCP name of the sampling strategy.
         */
        public String katcpName() {
            return name().toLowerCase();
        }

        /**
         * Find a strategy for the given name.
         *
         * @param name  The KATCP strategy name.
         * @return  The Strategy enum value for the KATCP name.
         */
        public static Strategy fromKatcpName(String name) {
            Strategy strat;
            try {
                strat = Strategy.valueOf(Strategy.class, name.toUpperCase());
            }
            catch (IllegalArgumentException e) {
                throw new IllegalArgumentException(String.format("Unknown sensor sampling strategy name '%s'", name));
            }
            return strat;
        }
    }

    // Interface methods

    /**
     * Return the strategy type.
     *
     * @return  The Strategy enum representing the type of sampling.
     */
    Strategy getType();

    /**
     * Return the formatted strategy parameters.
     *
     * @return  List of parameters for the sampling strategy as Strings.
     */
    String[] getStrategyParameters();

}
